# $Id: PKGBUILD 83614 2013-02-03 23:11:33Z arodseth $
# Maintainer: Alexander Rødseth <rodseth@gmail.com>
# Contributor: Chris Brannon <cmbrannon79@gmail.com>
# Contributor: JJDaNiMoTh <jjdanimoth@gmail.com>
# Contributor: Bjørn Lindeijer <bjorn lindeijer nl>

pkgname=dumb
pkgver=0.9.3
pkgrel=7
pkgdesc='IT, XM, S3M and MOD player library'
arch=('x86_64' 'i686')
license=('custom:dumb' 'GPL')
url='http://dumb.sourceforge.net/'
makedepends=('setconf')
depends=('glibc' 'allegro4')
source=("http://downloads.sourceforge.net/sourceforge/dumb/$pkgname-$pkgver.tar.gz"
        'as-needed.patch'
        'CVE-2006-3668.patch')
sha256sums=('8d44fbc9e57f3bac9f761c3b12ce102d47d717f0dd846657fb988e0bb5d1ea33'
            'f7a41576d5dcecad2f9a01cbb0228457b434423046cb67c9a0a720ec87f43fb9'
            '9f6785435757db725bc73b1c4874b91e80b9277c6fdd2b56e47dae1cfbc968e6')

build() {
  cd "$srcdir/$pkgname-$pkgver"

  # Add -fPIC for anything but i686
  [ "$CARCH" = 'i686' ] || export CFLAGS="${CFLAGS} -fPIC"

  # Patch from Gentoo for CVE-2006-3668
  patch -p1 < "$srcdir/CVE-2006-3668.patch"

  # Patch from Gentoo for binutils >= 2.22
  patch -p1 < "$srcdir/as-needed.patch"
  sed -i '/LDFLAGS :=/d' Makefile
  cp Makefile Makefile.rdy

  # Make with Allegro support
  # Upstream's make process is interactive, and we can't simply pass
  # a here-document to the make command.  The best way is to write our
  # own config.txt, circumventing the interactive configuration step,
  # as is done in Gentoo's ebuild.
	cat << EOF > make/config.txt
include make/unix.inc
ALL_TARGETS := core core-examples core-headers
ALL_TARGETS += allegro allegro-examples allegro-headers
PREFIX := /usr
EOF

  # Use OFLAGS to be able to set CFLAGS without replacing the -I directives
  make -j1 OFLAGS="${CFLAGS}"
}

package() {
  cd "$srcdir/$pkgname-$pkgver"

  install -d "$pkgdir"/usr/{lib,bin,include}
  install -Dm644 licence.txt \
    "$pkgdir/usr/share/licenses/$pkgname/licence.txt"
  setconf make/config.txt PREFIX "$pkgdir/usr"
  make DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:
